package com.forum.framework.common.enums;

import cn.hutool.core.util.ArrayUtil;
import com.forum.framework.common.core.IntArrayValuable;

import java.util.Arrays;

/**
 * @author zihan.ouyang
 */
public enum UserTypeEnum implements IntArrayValuable {
    ADMIN(1, "管理员"),
    USER(2, "用户"),
    ;

    public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(UserTypeEnum::getValue).toArray();
    private final Integer value;

    private final String name;

    UserTypeEnum(String name, Integer value) {
        this.name = name;
        this.value = value;
    }

    private UserTypeEnum(Integer value, String name) {
        this.value = value;
        this.name = name;
    }

    public Integer getValue() {
        return value;
    }

    public String getName() {
        return name;
    }

    public static UserTypeEnum valueOf(Integer value) {
        return ArrayUtil.firstMatch(userTypeEnum -> userTypeEnum.getValue().equals(value), UserTypeEnum.values());
    }


    @Override
    public int[] array() {
        return ARRAYS;
    }
}
